using SimpleObjectPool;
using System.Collections;
using UnityEngine;

public class ObjectPoolGameObjec : MonoBehaviour
{
    private PoolUnityObject<GameObject> fishPool;

    private void Awake()
    {
        fishPool = new PoolUnityObject<GameObject>(FuncCreate , (go) => go.SetActive(true), (go) => go.SetActive(false), 10);
    }

    void Start()
    {
        Debug.LogError($"Init CurCount:{fishPool.CurCount}");

        GameObject fishOne = fishPool.Spawn();
        Debug.LogError($"Spawn 1 CurCount:{fishPool.CurCount}");

        fishPool.Return(fishOne);
        Debug.LogError($"Return 1 CurCount:{fishPool.CurCount}");

        StartCoroutine(PickFish());
    }

    private IEnumerator PickFish()
    {
        GameObject tmp;
        for (int i = 0; i < 10; i++)
        {
            tmp = fishPool.Spawn();
            Debug.LogError($"PickFish Spawn CurCount:{fishPool.CurCount}");
            yield return new WaitForSeconds(0.5f);
            fishPool.Return(tmp);
            Debug.LogError($"PickFish Return CurCount:{fishPool.CurCount}");
        }
    }
    private GameObject FuncCreate()
    {
        GameObject go = new GameObject();
        go.SetActive(false);
        return go;
    }
}